<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8" />
    <title>Toast - isOpen</title>
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"
    />
    <link href="../../../../../css/ionic.bundle.css" rel="stylesheet" />
    <link href="../../../../../scripts/testing/styles.css" rel="stylesheet" />
    <script src="../../../../../scripts/testing/scripts.js"></script>
    <script type="module" src="../../../../../dist/ionic/ionic.esm.js"></script>
  </head>

  <body>
    <ion-app>
      <ion-header>
        <ion-toolbar>
          <ion-title>Toast - isOpen</ion-title>
        </ion-toolbar>
      </ion-header>

      <ion-content class="ion-padding">
        <button id="default" onclick="openToast()">Open Toast, 2s Duration</button>
        <button id="timeout" onclick="openToast(500)">Open Toast, Close Manually After 500ms</button>

        <ion-toast message="Hello World" duration="2000"></ion-toast>
      </ion-content>
    </ion-app>

    <script>
      const toast = document.querySelector('ion-toast');

      const openToast = (timeout) => {
        toast.isOpen = true;

        if (timeout) {
          setTimeout(() => {
            toast.isOpen = false;
          }, timeout);
        }
      };

      toast.addEventListener('ionToastDidDismiss', () => {
        toast.isOpen = false;
      });
    </script>
  </body>
</html>
